package com.ti.demo.configuration;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.mcp.customizer.McpAsyncClientCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @description: MCP 客户端配置
 * @Author Triagen
 * @Date 2025/10/17 9:42
 */
@Slf4j
@Configuration
public class McpClientConfiguration {

    /**
     * 服务端工具变动通知日志记录，Spring AI已有此实现，这里拎出来是为了方便查看
     * <p>
     * McpClientAutoConfiguration：McpAsyncClientCustomizer 被应用于 McpClient.AsyncSpec，McpClient.AsyncSpec 被用于创建 McpAsyncClient，其 toolsChangeConsumers 用于处理工具变动通知，接收工具列表
     */
    @Bean
    public McpAsyncClientCustomizer toolsChangeLog() {
        return (name, spec) -> {
            // 添加工具变动信息消费者
            spec.toolsChangeConsumer(tools -> Mono.fromRunnable(() -> log.info("Tools changed: {}", tools)));
        };
    }

}
